#include "cNPC.h"
#include "cPath.h"
#include "cScene.h"
#include <cstdlib>

cNPC::cNPC(void)
{
	isEnemy = false;

	cx = 0;
	cy = 0;
	x = 0;
	y = 0;

	animSeq = 0;
	animDelay = 0;
}

cNPC::~cNPC(void)
{
}

bool cNPC::IsEnemy()
{
	return isEnemy;
}
void cNPC::IsEnemy(bool isIt)
{
	isEnemy= isIt;
}

void cNPC::SetPosition(int posx, int posy)
{
	x = posx;
	y = posy;
}
void cNPC::GetPosition(int *posx, int *posy)
{
	*posx = x;
	*posy = y;
}
void cNPC::SetCell(int cellx, int celly)
{
	cx = cellx;
	cy = celly;
}
void cNPC::GetCell(int *cellx, int *celly)
{
	*cellx = cx;
	*celly = cy;
}

void cNPC::SetTextCoords(int x, int y)
{
	tx = x;
	ty = y;
}

void cNPC::GetRect(RECT *rc, int *posx, int *posy, cScene *scene)
{
	int sCx, sCy;
	scene->GetSceneOrigin(&sCx, &sCy);

	*posx = SCENE_Xo + x - (sCx<<5);
	*posy = SCENE_Yo + y - (sCy<<5);

	switch(path.Faced() )
	{
		case STOP:
			SetRect(rc, tx, ty, tx+32, ty+32);
			break;
		case N:
			SetRect(rc, tx+32, ty+((animSeq)<<5), tx+64, ty+((animSeq+1)<<5) );
			break;
		case S:
			SetRect(rc, tx, ty+((animSeq)<<5), tx+32, ty+((animSeq+1)<<5) );
			break;
		case SE:
		case NE:
		case E:
			SetRect(rc, tx+96, ty+((animSeq)<<5), tx+128, ty+((animSeq+1)<<5) );
			break;
		case SO:
		case NO:
		case O:
			SetRect(rc, tx+64, ty+((animSeq)<<5), tx+96, ty+((animSeq+1)<<5) );
			break;
	}
	if(!path.IsDone() )
	{
		++animDelay;
		if(animDelay == 4)
		{
			++animSeq;
			if(animSeq == 3) animSeq = 0;
			animDelay = 0;
		}
	}
}

void cNPC::GetRectRadar(RECT *rc, int *posx, int *posy)
{
	*posx = RADAR_Xo + ( cx << 2 );
	*posy = RADAR_Yo + ( cy << 2 );

	SetRect(rc, 84, 32, 88, 36);
}